<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>拼团旅游线路</title>
    <script src="__PUBLIC__/echarts/echarts.min.js"></script>

    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
    <style>
        #grouptours tr th,td{
            text-align:center
        }
    </style>
</head>

<body>
<div class="layui-fluid main">
    <fieldset class="layui-elem-field site-demo-button" style="margin-top: 30px;border:0">
        <div class="layui-form-item" style="float: left;">
            <form class="layui-form serch" action="/admin/grouptoursline/index" method="post">
                <div class="layui-form-item" style="float: left;">
                    <div class="layui-input-inline">
                        <input type="text" name="title" lay-verify="title" value="{if isset($wherelist['title'])}{$wherelist['title']}{/if}" autocomplete="off" placeholder="请输入线路名称/产品code" class="layui-input layui-btn-sm">
                    </div>
                    <button class="layui-btn layui-btn-danger layui-btn-sm" lay-submit="" lay-filter="serch">搜索</button>
                    <a href="{:url('admin/grouptoursline/edit')}" class="layui-btn layui-btn-sm a_menu">
                        <i class="layui-icon layui-icon-add-1">+</i>普通拼线路
                    </a>
                    <a href="{:url('admin/grouptoursline/editFree')}" class="layui-btn layui-btn-sm layui-btn-warm a_menu">
                        <i class="layui-icon layui-icon-add-1">+</i>自由拼线路
                    </a>
                    <!--<a class="layui-btn layui-btn-sm layui-btn-danger reflushData">-->
                        <!--刷新缓存-->
                    <!--</a>-->
                </div>
            </form>

        </div>
    </fieldset>
    <table class="layui-table" lay-even="" lay-skin="line" id="grouptours">
        <colgroup>
            <col width="50">
            <col width="100">
            <col width="100">
            <col width="80">
            <col width="60">
            <col width="60">
            <col width="80">
            <col width="100">
            <col width="80">
            <col width="100">
            <col width="80">
            <col width="80">
            <col width="120">
            <col width="80">
        </colgroup>
        <thead>

        <tr>
            <th >ID</th>
            <th >线路名称</th>
            <th >图片</th>
            <th >城市</th>
            <th >天数</th>

            <th >产品ID</th>
            <th >商品ID</th>
            <th >商品状态</th>
            <th >是否推荐</th>
            <th >权重</th>
            <th >销量</th>
            <th >是否启用</th>
            <th >创建时间</th>
            <th >操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="list" id="vo"}
        <tr>
            <td>{$vo.line_id}</td>
            <td>
                <strong>{$vo.title}</strong>
                {if $vo.is_free==1}
                <span class="layui-badge layui-bg-orange">自由拼</span>
                {/if}
            </td>
            <td>
                <img src="{$vo.img}" width="150" alt="">
            </td>
            <td>{$vo.city_name}</td>
            <td>{$vo.days}</td>
            <td>{notempty name='vo.trip_id'}<a href="{:url('admin/product/preview',['id'=>$vo['trip_id']])}" target="_blank" class="layui-btn layui-btn-primary layui-btn-sm" title="{$vo.trip_name}">{$vo.trip_id}</a>{/notempty}</td>
            <td>{notempty name='vo.product_id'}
                <!--<a href="{:url('admin/goods/addgoods',['id'=>$vo['product_id']])}" class="layui-btn layui-btn-primary layui-btn-sm" title="{$vo.product_name}">-->
                    {$vo.product_id}
                <!--</a>-->
                {/notempty}
            </td>
            <td>{if $vo.goods_status==1}售卖中{elseif $vo.goods_status==2}已下架{elseif $vo.goods_status==3}已售罄{/if}</td>
            <td>
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="margin:10px">
                            <input type="checkbox" name="is_recommend" value="1" data-id="{$vo.line_id}" lay-filter="changeRecommend" lay-skin="switch" <?php if($vo['is_recommend']==1){ echo 'checked';} ?> lay-text="推荐|普通">
                        </div>
                    </div>
                </form>
            </td>
            <td>
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="margin:10px">
                            <input class="layui-input changeSortNum" type="number" name="sort_num" value="{$vo.sort_num}" data-old="{$vo.sort_num}" data-id="{$vo.line_id}">
                        </div>
                    </div>
                </form>
            </td>
            <td>{$vo.total_sold}</td>
            <td>
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="margin:10px">
                            <input type="checkbox" name="is_use" value="1" data-id="{$vo.line_id}" lay-filter="changeUse" lay-skin="switch" <?php if($vo['is_use']==1){ echo 'checked';} ?> lay-text="开启|禁用">
                        </div>
                    </div>
                </form>
            </td>

            <td>{$vo.create_time}</td>
            <td class="operation-menu">
                <!--<a href="{:url('admin/goods/addclassify')}?id={$vo.product_id}" class="layui-btn layui-btn-xs layui-btn-warm a_menu"  style="margin-right: 0;margin-top:2px;font-size:12px;background: #51a954">商品套餐设置</a>-->
                <!--<a href="{:url('admin/goods/personsedit')}?id={$vo.product_id}" class="layui-btn layui-btn-xs layui-btn-warm"  style="margin-right: 0;margin-top:2px;font-size:12px;background: darkslategrey">商品价格设置</a>-->
                {if $vo.is_free < 1}
                <a href="{:url('admin/grouptoursline/edit',['id'=>$vo.line_id])}" class="layui-btn layui-btn-xs layui-btn-info a_menu"  style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">编辑</a>
                {else}
                <a href="{:url('admin/grouptoursline/editfree',['id'=>$vo.line_id])}" class="layui-btn layui-btn-xs layui-btn-warm a_menu"  style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">编辑</a>
                {/if}
                <a class="layui-btn layui-btn-xs layui-btn-danger delete" codeid="{$vo.line_id}" style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">删除</a>
                <a href="{:url('admin/grouptoursline/specs',['id'=>$vo.line_id])}" class="layui-btn layui-btn-xs layui-btn-info a_menu"  style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">套餐</a>
                {if $vo.qrcode_id < 1}
                <!--<a href="{:url('admin/grouptoursline/addqrcode')}?line_id={$vo.line_id}" class="layui-btn layui-btn-xs layui-btn-normal addqrcode"  style="margin-right: 0;margin-top:2px;font-size:12px;">添加群</a>-->
                {else}
                {if $now_time >= $vo.qrcode_expire_time}
                <!--<a href="{:url('admin/grouptoursline/addqrcode')}?id={$vo.qrcode_id}" class="layui-btn layui-btn-xs layui-btn-warm addqrcode"  style="margin-right: 0;margin-top:2px;font-size:12px;">更新群</a>-->
                {else}
                <!--<a href="{:url('admin/grouptoursline/addqrcode')}?id={$vo.qrcode_id}" class="layui-btn layui-btn-xs layui-btn-info addqrcode"  style="margin-right: 0;margin-top:2px;font-size:12px;">修改群</a>-->
                {/if}
                {/if}
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div>{$list->render()}</div>

    <script src="__PUBLIC__/layui/layui.js"></script>
    <script src="__PUBLIC__/jquery/jquery.min.js"></script>


    <script type="text/javascript">

        $('.delete').click(function(){
            var id = $(this).attr('codeid');
            layer.confirm('确定要删除?', function(index) {
                $.ajax({
                    url:"{:url('admin/grouptoursline/del')}",
                    data:{id:id},
                    type:'post',
                    async: false,
                    success:function(res) {
                        layer.msg(res.msg);
                        if(res.code == 1) {
                            setTimeout(function(){
                                location.reload();
                            },1500)
                        }
                    }
                })
            })
        })
    </script>
    <script type="text/javascript">
        layui.use(['layer','form'],function(){
            var layer = layui.layer;
            var form = layui.form;
            $('.a_menu').click(function(){
                var url = $(this).attr('href');
                var a = 0;
                $.ajax({
                    url:url
                    ,async:false
                    ,success:function(res){
                        if(res.code == 0) {
                            layer.msg(res.msg);
                            a = 1;
                        }
                    }
                })
                if(a === 0) {
                    layer.open({
                        type:2,
                        content:url,
                        area: ['60%', '90%'],
                        end:function(){
                            location.reload();
                        }
                    });
                }
                return false;
            })
            $(".addqrcode").click(function(){
                var url = $(this).attr('href');
                layer.open({
                    type:2,
                    content:url,
                    area: ['60%', '90%'],
                    end:function(){
                        location.reload();
                    }
                });
                return false;
            })

            $(".reflushData").click(function(){
                layer.confirm('确定要刷新关联的商品和产品的数据?', function(index) {
                    $.ajax({
                        url:"{:url('admin/Grouptoursline/reflushData')}",
                        data:{},
                        type:'post',
                        async: false,
                        success:function(res) {
                            layer.msg(res.msg);
                        }
                    })
                })
            })

            //切换禁用启用
            form.on('switch(changeUse)', function(data){
                var id= $(this).attr('data-id')
                var is_use;

                if(data.elem.checked){
                    is_use =1;
                }else{
                    is_use =0;
                }
                $.ajax({
                    url:"{:url('admin/grouptoursline/changeUse')}",
                    data:{'id':id,'is_use':is_use},
                    type:'post',
                    async: false,
                    success:function(res) {
                        layer.msg(res.msg);
                    }
                })

            });

            //切换禁用启用
            form.on('switch(changeRecommend)', function(data){
                var id= $(this).attr('data-id')
                var is_recommend;

                if(data.elem.checked){
                    is_recommend =1;
                }else{
                    is_recommend =0;
                }
                $.ajax({
                    url:"{:url('admin/grouptoursline/changeRecommend')}",
                    data:{'id':id,'is_recommend':is_recommend},
                    type:'post',
                    async: false,
                    success:function(res) {
                        layer.msg(res.msg);
                    }
                })

            });

            //修改权重信息
            $(".changeSortNum").change(function(){
                var sort_num = parseInt($(this).val());
                var old_sort_num = parseInt($(this).attr("data-old"));
                if(sort_num<1){
                    $(this).val(old_sort_num);
                    layer.msg("请输入大于0的数字");
                }else{
                    var _that = this;
                    var id = $(this).attr("data-id");
                    $.ajax({
                        url:"{:url('admin/grouptoursline/changeSortNum')}",
                        data:{'id':id,'sort_num':sort_num},
                        type:'post',
                        async: false,
                        success:function(res) {
                            layer.msg(res.msg);
                            if(res.code!=1){
                                $(_that).val(old_sort_num);
                            }else{
                                setTimeout(function(){
                                    window.location.reload();
                                },1000);
                            }
                        }
                    })
                }
            })
        });
    </script>

</div>
</body>
</html>
